<template>
	<view class="register">
		<view class="register_right">
			<view @click="getDepartId(item)" v-for="item,index in departmentList" :key="item._id"
				class="register_right_item">
				{{item.dep_ment}}
			</view>
		</view>
		<view class="register_left">
			<view class="register_left_item" v-if="this.fid == this.getRegList[0]._id"
				v-for="item,index in getRegList[0].dep_ment_list" :key="item.dep_id" @click="handleRegist(item)">
				{{item.dep_name}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getDepartment,
		getReglist,
		getTimesele
	} from '../../utils/api.js'
	export default {
		data() {
			return {
				departmentList: [],
				fid: 'af2b6af462e1780b000b7ac649eef401',
				getRegList: []
			};
		},
		methods: {
			// 点击详情
			handleRegist(item) {
				console.log(item);
				uni.navigateTo({
					url: '/pages/detailed/detailed?id=' + item.dep_id
				})
			},
			// 获取父科室
			getDepartmentList() {
				getDepartment().then(res => {
					console.log(19, res);
					this.departmentList = res.data.data
				})
			},
			// 获取父科室ID
			getDepartId(item) {
				this.fid = item._id
				getReglist({
					id: this.fid
				}).then(res => {
					console.log(36, res);
					this.getRegList = res.data.data
					console.log(47, this.getRegList[0]._id);
				})
			},
			// 获取子科室
			// getReg() {
			// 	getReglist({
			// 		id: this.fid
			// 	}).then(res => {
			// 		console.log(36, res);
			// 		this.getRegList = res.data.data
			// 		console.log(47, this.getRegList[0]._id);
			// 	})
			// }
		},
		created() {
			// 获取父科室
			this.getDepartmentList()
			// 获取子科室
			// this.getReg()
			getReglist({
				id: this.fid
			}).then(res => {
				console.log(36, res);
				this.getRegList = res.data.data
				console.log(47, this.getRegList[0]._id);
			})
		}
	}
</script>

<style lang="scss">
	.register {
		width: 750rpx;

	}

	.register_right {
		height: 100rpx;
		width: 200rpx;
		display: flex;
		flex-wrap: wrap;
		float: left;
		margin-right: 40rpx;
	}

	.register_right_item {
		width: 100%;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		background: #ddd;
	}

	.register_left {
		float: left;
	}

	.register_left_item {
		margin-left: 40rpx;
		margin: 20rpx 0;
	}
</style>